﻿/*
* ========================================================================
* 类说明：
*   AVSV操作类
* 
* 作者：HGS   时间：2024/9/5 19:52:58
* 
* 修改者：         时间：           
* 修改说明：
* ========================================================================
*/

using EasyTest.Shared.EnumType;
using EasyTest.Shared.TestAttribute;
using EasyTest.Shared.外部访问;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ZLGCANoptimize
{
    public class AVSV
    {
        //static ZLGCANHelper zLGCANHelper = null;
        //static List<ZCAN_Receive_Data> zCAN_Receive_Datas = null;

        [ExposedMethodAttribute("")]
        public bool 打开AVSV(int 通道, out string 返回信息)
        {
            返回信息 = string.Empty;

            try
            {
                //初始化
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    返回信息 = "启动can设备失败";
                    return false;
                }

                ////CAN通道解密
                //bool OK = Can.解密(通道,new List<ZCAN_Receive_Data>(), out 返回信息);
                //if (!OK)
                //{
                //    return false;
                //}

                //发送报文
                bool result1 = false;
                for (int i = 0; i < 3; i++)
                {
                    result1 = zLGCANHelper.SentData(通道, 0x1F5, "00 00 00 02 00 00 00 00", true, SendType.正常发送);
                    System.Threading.Thread.Sleep(50);
                    result1 = zLGCANHelper.SentData(通道, 0x1A9, "00 00 00 00 0A 00 00 00", true, SendType.正常发送);
                }
                if (!result1)
                {
                    返回信息 = "发送数据失败,打开AVSV失败";
                    return false;
                }

                返回信息 = "打开AVSV成功";
                return true;
            }
            catch (Exception ex)
            {
                返回信息 = ex.Message;
               // LogHelper.Error($"[AVSV.打开AVSV]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[AVSV.打开AVSV]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 关闭AVSV(int 通道, out string 返回信息)
        {
            返回信息 = string.Empty;

            try
            {
                //初始化
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    返回信息 = "启动can设备失败";
                    return false;
                }

                ////CAN通道解密
                //bool OK = Can.解密(通道,new List<ZCAN_Receive_Data>(), out 返回信息);
                //if (!OK)
                //{
                //    return false;
                //}

                //发送报文
                bool result1 = false;
                for (int i = 0; i < 3; i++)
                {
                    result1 = zLGCANHelper.SentData(通道, 0x1F5, "00 00 00 01 00 00 00 00", true, SendType.正常发送);
                    System.Threading.Thread.Sleep(50);
                    result1 = zLGCANHelper.SentData(通道, 0x1A9, "00 00 00 00 0A 00 00 00", true, SendType.正常发送);
                }
                if (!result1)
                {
                    返回信息 = "发送数据失败,关闭AVSV失败";
                    return false;
                }

                返回信息 = "关闭AVSV成功";
                return true;
            }
            catch (Exception ex)
            {
                返回信息 = ex.Message;
                //LogHelper.Error($"[AVSV.关闭AVSV]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[AVSV.关闭AVSV]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }
    }
}
